package home.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.alibaba.android.vlayout.DelegateAdapter;
import com.alibaba.android.vlayout.LayoutHelper;
import com.alibaba.android.vlayout.layout.SingleLayoutHelper;

import net.ck.hzq.R;
import net.ck.hzq.TobuyApplication;

import activity.WorkOrderListActivity;
import pos.OpenPosActivity;
import ui.activity.profit.TradeRecordAct;

public class MerchantServiceAdapter extends DelegateAdapter.Adapter<MerchantServiceAdapter.MerchantServiceVH> {

    private final Context mContext;

    public MerchantServiceAdapter(Context context) {
        mContext = context;
    }

    public void setupData() {

    }

    @Override
    public LayoutHelper onCreateLayoutHelper() {
        return new SingleLayoutHelper();
    }

    @NonNull
    @Override
    public MerchantServiceVH onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        return new MerchantServiceVH(LayoutInflater.from(mContext).inflate(R.layout.item_home_merchant_service, viewGroup,
                false));
    }

    @Override
    public void onBindViewHolder(@NonNull MerchantServiceVH holder, int i) {
        holder.openPosLayout.setOnClickListener(view -> {

            if (!TobuyApplication.isAuthed()) {
                Toast.makeText(mContext, "请进行实名认证", Toast.LENGTH_SHORT).show();
                return;
            }
            OpenPosActivity.start(mContext);
        });
        holder.tradeRecordLayout.setOnClickListener(view -> {
            if (!TobuyApplication.isAuthed()) {
                Toast.makeText(mContext, "请进行实名认证", Toast.LENGTH_SHORT).show();
                return;
            }
            mContext.startActivity(new Intent(mContext,TradeRecordAct.class));
//            TradeRecordActivity.start(mContext);
        });
        holder.workOrderLayout.setOnClickListener(view -> {
            if (!TobuyApplication.isAuthed()) {
                Toast.makeText(mContext, "请进行实名认证", Toast.LENGTH_SHORT).show();
                return;
            }
            WorkOrderListActivity.start(mContext);
        });
    }

    @Override
    public int getItemCount() {
        return 1;
    }

    class MerchantServiceVH extends RecyclerView.ViewHolder {
        private View openPosLayout;
        private View tradeRecordLayout;
        private View workOrderLayout;

        MerchantServiceVH(@NonNull View itemView) {
            super(itemView);
            openPosLayout = itemView.findViewById(R.id.pos_open_layout);
            tradeRecordLayout = itemView.findViewById(R.id.trade_record_layout);
            workOrderLayout = itemView.findViewById(R.id.work_order_layout);
        }
    }

}
